<div class="layuimini-main">
        <blockquote class="layui-elem-quote">
            这里是一个系统通知，可在后台进行设定
        </blockquote>
        <!--        <button type="button" class="layui-btn" id="test1">-->
        <!--            <i class="layui-icon">&#xe67c;</i>上传图片-->
        <!--        </button>-->
        <!--                <div id="photoUpload" class="photoUpload"></div>-->
        <form class="layui-form layuimini-form" action="">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>资源信息</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">选择资源</label>
                <div class="layui-input-inline">
                    <input type="file" id="upload-file" name="upload-file" class="layui-input"/>
                    <!--                    <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入相册标题"-->
                    <!--                           class="layui-input">-->
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入资源标题"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">简介</label>
                <div class="layui-input-block">
                    <textarea name="describe" autocomplete="off" placeholder="请输入资源简介" class="layui-input"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否公开</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isPublic" lay-skin="switch" lay-text="是|否">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">拍摄日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="date" id="date" lay-verify="date" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">拍摄地点</label>
                <div class="layui-input-inline">
                    <input type="text" name="location" lay-verify="location" autocomplete="off" placeholder="请输入拍摄地点"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </form>
    </div>
<script type="text/javascript">

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId2', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var albumId = localStorage.getItem("selectedAlbumId");
            var isPub = true;
            if (data.field.isPublic === 'off') {
                isPub = false;
            }
            jq1111.ajax({
                type: "POST",
                crossDomain: true,
                url: "http://localhost:5000/api/PersonalAlbum/Add",
                contentType: "application/json",
                dataType: "json",
                xhrFields: {
                    withCredentials: true
                },
                data: JSON.stringify({
                    "albumId": albumId,
                    "title": data.field.title,
                    "description": data.field.description,
                    "isPublic": isPub,
                    "file": data.field.upload - file,
                    "shootingDate": data.field.date,
                    "location": data.field.location,
                }),
                success: function (message) {
                    console.log(message);
                    layer.alert(message.msg, {
                        title: '操作结果'
                    })
                },
                error: function (message) {
                    console.log(message.responseJSON);
                    layer.alert(message.responseJSON.msg, {
                        title: '操作结果'
                    })
                },
            });

            return false;
        });

        form.render();

    });
</script>